function creardatatable() {

	Context.VigenciaEditor = new Y.widget.DropdownCellEditor({
		dropdownOptions : Context.VigenciaCatalog,
		disableBtns : false,

		LABEL_SAVE : "Aceptar",
		LABEL_CANCEL : "Cancelar"
	});

	Context.VigenciaFormatter = function(cell, row, col, data) {
		var combo = Context.VigenciaCatalog;
		for (var i = 0; i < combo.length; i++) {
			if (data == combo[i].value) {
				cell.innerHTML = combo[i].label;
				return;
			}
		}
	};

	var detalleFormatter = function(cell, row, col, data) {
		cell.innerHTML = '<div style="text-align: center"><input type="image" src="'
				+ Z.zuictx
				+ '/edit.gif" value="Detalle" size="21,21" style="width:21px;height:21px"  border="0" alt="Detalle" onclick="return false;"/></div>';
	};

	var eliminarFormatter = function(cell, row, col, data) {
		cell.innerHTML = '<div style="text-align: center"><input type="image" src="'
				+ Z.zuictx
				+ '/trash.gif" value="Eliminar" size="21,21" style="width:21px;height:21px" border="0" alt="Eliminar" onclick="return false;"/></div>';
	};

	var myColumnDefs = [ {
		key : "idConnection",
		label : "ID"
	}, {
		key : "idCountry",
		label : "PAIS"
	}, {
		key : "username",
		label : "USUARIO"
	}, {
		key : "password",
		label : "PASSWORD"
	}, {
		key : "url",
		label : "URL"
	}, {
		key : "vigente",
		label : "*ESTATUS",
		formatter : Context.VigenciaFormatter,
		editor : Context.VigenciaEditor
	}, {
		key : "modificado",
		label : "EDITAR",
		formatter : detalleFormatter
	}, {
		key : "eliminar",
		label : "ELIMINAR",
		formatter : eliminarFormatter
	} ];

	try {
		var config = {};
		config.URL = Context.Registros;
		config.FIELDS = [ "idConnection", "idCountry", "descCountry", "username", "password", "url",
				"vigente",  "eliminado", "modificado", "nuevo" ];
		config.COLUMNS = myColumnDefs;
		config.DATATABLE_DIV = "datatable";
		config.PAGINATOR_DIV = "paginator";
		config.TOTAL_REGISTROS_DIV = "totalregistros";
		config.ROW_PER_PAGE = 10;

		Context.table = new Z.Table(config);
		myDataTable = Context.table.getDatatable();

		myDataTable.subscribe("buttonClickEvent", function(oArgs) {

			var target = oArgs.target;
			var record = this.getRecord(target);
			if (target.value == "Detalle") {
				editar(record);
			} else if (target.value == "Eliminar") {
				myDataTable.eliminarRegistro(record);
			} else {
				alert("buttonClickEvent value desconocido: " + target.value);
			}
			return false;

		});

		myDataTable.subscribe("rowClickEvent", function(oArgs) {
			var target = oArgs.target;
			var record = this.getRecord(target);

			var rol = record.getData('idRol');
			if (rol == 'IM_USER') {
				Z.mercAgregarButton.set("disabled", true);
				Z.mercGuardarButton.set("disabled", true);
				Context.tablem.clear();
				return;
			}
			try {
				var f = document.getElementById("usernameForm");
				f.elements['username'].value = record.getData('username');

				var callback = new Z.JsonCall();
				callback.exito = function(data) {
					Z.mercAgregarButton.set("disabled", false);
					Z.mercGuardarButton.set("disabled", false);
					myDataTablem.insertar(data.ResultSet.Result);
				};
				callback.fallo = function(messages) {
					alert("error")
				};

				Z.ShowWait();
				Context.tablem.clear();
				Y.util.Connect.setForm(f);
				var request = Y.util.Connect.asyncRequest('POST', Context.MercanciasUsername, callback);

			} catch (e) {
				alert("mercancia: " + e + e.description);
			}

		});

		myDataTable.subscribe("editorSaveEvent", function(oArgs) {
			try {
				var oRecord = oArgs.editor.getRecord();
				var elCell = oArgs.editor.getTdEl();
				if (oArgs.newData != oArgs.oldData) {

					var elRow = this.getTrEl(elCell);

					oRecord.setData("modificado", true);
					myDataTable.render();
				}
			} catch (e) {
				alert("editorSaveEvent:" + e + " " + e.description)
			}
		});

	} catch (e) {
		alert(e);
	}

	myDataTable.insertarRegistro = function(oData) {
		try {
			var dtbl = Context.table.getDatatable();
			oData['nuevo'] = true;
			oData['modificado'] = false;
			oData['eliminado'] = false;
			dtbl.addRow(oData, 0);
			myDataTable.render();
			Context.dialog1.hide();
		} catch (x) {
			alert("insertarRegistro: " + x.description + x.message);
			return false;
		}
	};

	myDataTable.actualizarRegistro = function(oData) {
		try {
			var nRecordsLength = myDataTable.getRecordSet().getLength();
			var record;

			for (i = 0; i < nRecordsLength; i++) {
				record = myDataTable.getRecordSet().getRecord(i);
				if (record.getId() == oData['recordid']) {

					record.setData("username", oData['username']);
					record.setData("password", oData['password']);
					record.setData("nombre", oData['nombre']);
					record.setData("idPais", oData['idPais']);
					record.setData("pais", oData['pais']);
					record.setData("rol", oData['rol']);
					record.setData("idRol", oData['idRol']);
					record.setData("vigente", oData['vigente']);
					record.setData("modificado", true);

					Context.dialog1.hide();
					break;
				}
			}

			myDataTable.render();
		} catch (x) {
			alert("actualizarRegistro: " + x + x.description);
		}
	};

	myDataTable.eliminarRegistro = function(record) {

		var ejecuta = true;

		if (record.getData("nuevo") == true
				|| record.getData("nuevo") == 'true') {
			myDataTable.deleteRow(record);
			ejecuta = false;
		}
		if (record.getData("eliminado") == true) {
			ejecuta = false;
			return;
		}
		if (ejecuta) {
			try {
				Context.eliminarDlg = new Y.widget.SimpleDialog("eliminarDlg",
						{
							width : "17em",
							fixedcenter : true,
							modal : true,
							visible : false,
							draggable : false
						});

				Context.eliminarDlg.setHeader("Confirmaci&oacute;n");
				Context.eliminarDlg.setBody("¿Desea borrar este usuario?");
				Context.eliminarDlg.cfg.setProperty("icon",
						Y.widget.SimpleDialog.ICON_WARN);

				var handleYes = function() {
					try {
						record.setData("eliminado", true);
						myDataTable.render();
						this.hide();
					} catch (e) {
						alert("eliminar handleYes: " + e + e.description);
					}
				};
				var handleNo = function() {
					this.hide();
				};
				var myButtons = [ {
					text : "Aceptar",
					handler : handleYes
				}, {
					text : "Cancel",
					handler : handleNo,
					isDefault : true
				} ];

				Context.eliminarDlg.cfg.queueProperty("buttons", myButtons);
				Context.eliminarDlg.render(document.body);
				Context.eliminarDlg.show();

			} catch (e) {
				alert("eliminar: " + e + e.description);
			}
		}
	};
}